using AppodealAds.Unity.Common;
using UnityEngine;

namespace AppodealAds.Unity.Android
{
	public class AndroidAppodealClient : IAppodealAdsClient
	{
		private AndroidJavaClass appodealClass;

		private AndroidJavaObject userSettings;

		private AndroidJavaObject activity;

		public AndroidJavaClass getAppodealClass()
		{
			if (appodealClass == null)
			{
				appodealClass = new AndroidJavaClass("com.appodeal.ads.Appodeal");
			}
			return appodealClass;
		}

		public AndroidJavaObject getActivity()
		{
			if (activity == null)
			{
				AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
				activity = androidJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
			}
			return activity;
		}

		public void initialize(string appKey, int adTypes)
		{
			getAppodealClass().CallStatic("initialize", getActivity(), appKey, adTypes);
		}

		public void setInterstitialCallbacks(IInterstitialAdListener listener)
		{
			getAppodealClass().CallStatic("setInterstitialCallbacks", new AppodealInterstitialCallbacks(listener));
		}

		public void setSkippableVideoCallbacks(ISkippableVideoAdListener listener)
		{
			getAppodealClass().CallStatic("setSkippableVideoCallbacks", new AppodealSkippableVideoCallbacks(listener));
		}

		public void setNonSkippableVideoCallbacks(INonSkippableVideoAdListener listener)
		{
			getAppodealClass().CallStatic("setNonSkippableVideoCallbacks", new AppodealNonSkippableVideoCallbacks(listener));
		}

		public void setRewardedVideoCallbacks(IRewardedVideoAdListener listener)
		{
			getAppodealClass().CallStatic("setRewardedVideoCallbacks", new AppodealRewardedVideoCallbacks(listener));
		}

		public void setBannerCallbacks(IBannerAdListener listener)
		{
			getAppodealClass().CallStatic("setBannerCallbacks", new AppodealBannerCallbacks(listener));
		}

		public void confirm(int adTypes)
		{
			getAppodealClass().CallStatic("confirm", adTypes);
		}

		public void cache(int adTypes)
		{
			getAppodealClass().CallStatic("cache", getActivity(), adTypes);
		}

		public bool isLoaded(int adTypes)
		{
			return getAppodealClass().CallStatic<bool>("isLoaded", new object[1] { adTypes });
		}

		public bool isPrecache(int adTypes)
		{
			return getAppodealClass().CallStatic<bool>("isPrecache", new object[1] { adTypes });
		}

		public bool show(int adTypes)
		{
			return getAppodealClass().CallStatic<bool>("show", new object[2]
			{
				getActivity(),
				adTypes
			});
		}

		public bool show(int adTypes, string placement)
		{
			return getAppodealClass().CallStatic<bool>("show", new object[3]
			{
				getActivity(),
				adTypes,
				placement
			});
		}

		public void hide(int adTypes)
		{
			getAppodealClass().CallStatic("hide", getActivity(), adTypes);
		}

		public void setAutoCache(int adTypes, bool autoCache)
		{
			getAppodealClass().CallStatic("setAutoCache", adTypes, autoCache);
		}

		public void setOnLoadedTriggerBoth(int adTypes, bool onLoadedTriggerBoth)
		{
			getAppodealClass().CallStatic("setOnLoadedTriggerBoth", adTypes, onLoadedTriggerBoth);
		}

		public void disableNetwork(string network)
		{
			getAppodealClass().CallStatic("disableNetwork", getActivity(), network);
		}

		public void disableNetwork(string network, int adTypes)
		{
			getAppodealClass().CallStatic("disableNetwork", getActivity(), network, adTypes);
		}

		public void disableLocationPermissionCheck()
		{
			getAppodealClass().CallStatic("disableLocationPermissionCheck");
		}

		public void disableWriteExternalStoragePermissionCheck()
		{
			getAppodealClass().CallStatic("disableWriteExternalStoragePermissionCheck");
		}

		public void requestAndroidMPermissions(IPermissionGrantedListener listener)
		{
			getAppodealClass().CallStatic("requestAndroidMPermissions", getActivity(), new AppodealPermissionCallbacks(listener));
		}

		public void orientationChange()
		{
			getAppodealClass().CallStatic("orientationChange");
		}

		public void setTesting(bool test)
		{
			getAppodealClass().CallStatic("setTesting", test);
		}

		public void setLogging(bool logging)
		{
			getAppodealClass().CallStatic("setLogging", logging);
		}

		public string getVersion()
		{
			return getAppodealClass().CallStatic<string>("getVersion", new object[0]);
		}

		public void trackInAppPurchase(double amount, string currency)
		{
			getAppodealClass().CallStatic("trackInAppPurchase", getActivity(), amount, currency);
		}

		public void setCustomRule(string name, bool value)
		{
			getAppodealClass().CallStatic("setCustomRule", name, value);
		}

		public void setCustomRule(string name, int value)
		{
			getAppodealClass().CallStatic("setCustomRule", name, value);
		}

		public void setCustomRule(string name, double value)
		{
			getAppodealClass().CallStatic("setCustomRule", name, value);
		}

		public void setCustomRule(string name, string value)
		{
			getAppodealClass().CallStatic("setCustomRule", name, value);
		}

		public void setSmartBanners(bool value)
		{
			getAppodealClass().CallStatic("setSmartBanners", value);
		}

		public void getUserSettings()
		{
			userSettings = getAppodealClass().CallStatic<AndroidJavaObject>("getUserSettings", new object[1] { getActivity() });
		}

		public void setUserId(string id)
		{
			userSettings.Call<AndroidJavaObject>("setUserId", new object[1] { id });
		}

		public void setAge(int age)
		{
			userSettings.Call<AndroidJavaObject>("setAge", new object[1] { age });
		}

		public void setBirthday(string bDay)
		{
			userSettings.Call<AndroidJavaObject>("setBirthday", new object[1] { bDay });
		}

		public void setEmail(string email)
		{
			userSettings.Call<AndroidJavaObject>("setEmail", new object[1] { email });
		}

		public void setGender(int gender)
		{
			switch (gender)
			{
			case 1:
				userSettings.Call<AndroidJavaObject>("setGender", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Gender").GetStatic<AndroidJavaObject>("OTHER") });
				break;
			case 2:
				userSettings.Call<AndroidJavaObject>("setGender", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Gender").GetStatic<AndroidJavaObject>("MALE") });
				break;
			case 3:
				userSettings.Call<AndroidJavaObject>("setGender", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Gender").GetStatic<AndroidJavaObject>("FEMALE") });
				break;
			}
		}

		public void setInterests(string interests)
		{
			userSettings.Call<AndroidJavaObject>("setInterests", new object[1] { interests });
		}

		public void setOccupation(int occupation)
		{
			switch (occupation)
			{
			case 1:
				userSettings.Call<AndroidJavaObject>("setOccupation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Occupation").GetStatic<AndroidJavaObject>("OTHER") });
				break;
			case 2:
				userSettings.Call<AndroidJavaObject>("setOccupation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Occupation").GetStatic<AndroidJavaObject>("WORK") });
				break;
			case 3:
				userSettings.Call<AndroidJavaObject>("setOccupation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Occupation").GetStatic<AndroidJavaObject>("SCHOOL") });
				break;
			case 4:
				userSettings.Call<AndroidJavaObject>("setOccupation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Occupation").GetStatic<AndroidJavaObject>("UNIVERSITY") });
				break;
			}
		}

		public void setRelation(int relation)
		{
			switch (relation)
			{
			case 1:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("OTHER") });
				break;
			case 2:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("SINGLE") });
				break;
			case 3:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("DATING") });
				break;
			case 4:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("ENGAGED") });
				break;
			case 5:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("MARRIED") });
				break;
			case 6:
				userSettings.Call<AndroidJavaObject>("setRelation", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Relation").GetStatic<AndroidJavaObject>("SEARCHING") });
				break;
			}
		}

		public void setAlcohol(int alcohol)
		{
			switch (alcohol)
			{
			case 1:
				userSettings.Call<AndroidJavaObject>("setAlcohol", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Alcohol").GetStatic<AndroidJavaObject>("NEGATIVE") });
				break;
			case 2:
				userSettings.Call<AndroidJavaObject>("setAlcohol", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Alcohol").GetStatic<AndroidJavaObject>("NEUTRAL") });
				break;
			case 3:
				userSettings.Call<AndroidJavaObject>("setAlcohol", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Alcohol").GetStatic<AndroidJavaObject>("POSITIVE") });
				break;
			}
		}

		public void setSmoking(int smoking)
		{
			switch (smoking)
			{
			case 1:
				userSettings.Call<AndroidJavaObject>("setSmoking", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Smoking").GetStatic<AndroidJavaObject>("NEGATIVE") });
				break;
			case 2:
				userSettings.Call<AndroidJavaObject>("setSmoking", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Smoking").GetStatic<AndroidJavaObject>("NEUTRAL") });
				break;
			case 3:
				userSettings.Call<AndroidJavaObject>("setSmoking", new object[1] { new AndroidJavaClass("com.appodeal.ads.UserSettings$Smoking").GetStatic<AndroidJavaObject>("POSITIVE") });
				break;
			}
		}
	}
}
